using System.Collections.Generic;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Model.StateCommands;
using StructureMap;

namespace Headspring.Training.Domain.Services.Impl
{
	[Pluggable(Keys.DEFAULT)]
	public class WorkflowFacilitator : IWorkflowFacilitator
	{
		public IStateCommand[] GetValidStateCommands(WorkOrder workOrder, Employee currentUser)
		{
			List<IStateCommand> commands = new List<IStateCommand>(GetAllStateCommands(workOrder, currentUser));
			commands.RemoveAll(delegate(IStateCommand obj) { return !obj.IsValid(); });

			return commands.ToArray();
		}

		public virtual IStateCommand[] GetAllStateCommands(WorkOrder workOrder, Employee currentUser)
		{
			List<IStateCommand> commands = new List<IStateCommand>();
			commands.Add(new SaveDraftCommand(workOrder, currentUser));
			commands.Add(new DraftToAssignedCommand(workOrder, currentUser));
			commands.Add(new AssignedToInProgressCommand(workOrder, currentUser));
			commands.Add(new InProgressToCompleteCommand(workOrder, currentUser));
			commands.Add(new DraftToCancelledCommand(workOrder, currentUser));
			commands.Add(new AssignedToCancelledCommand(workOrder, currentUser));
			commands.Add(new InProgressToCancelledCommand(workOrder, currentUser));
			commands.Add(new CompleteToAssignedCommand(workOrder, currentUser));
			return commands.ToArray();
		}
	}
}